package Work01;

public class Student {
    private String name;
    private String sex;
    private int age;

    public Student(int age) {
        this.age = age;
    }
    public Student(String name, String sex, int age) {
        this.name = name;
        this.sex = sex;
        this.age = age;
    }

    public Student() {

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }
    /*定义一个Student类，属性：姓名、性别、年龄。<br />在性别的set方法中判断是否是男/女，
    如果不是则抛出：性别异常<br />在年龄的set方法中判断年龄是否是15--50之间，如果不是则抛出：年龄异常*/
    public void setSex(String sex) {
        if (sex.equals("男")||sex.equals("女")){
            this.sex = sex;
        }else {
            throw new SexException("性别异常");
        }


    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age>15&&age<50){
            this.age = age;
        }else {
            throw new AgeException("年龄异常");
        }

    }

    @Override
    public String toString() {
        return "Student{" +
                "名字='" + name + '\'' +
                ", 性别='" + sex + '\'' +
                ", 年龄=" + age +
                '}';
    }
}
